﻿<UserControl xmlns:SubVersionOne="clr-namespace:SubVersionOne"  x:Class="SubVersionOne.WorkItemsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                   xmlns:vm="clr-namespace:SubVersionOne.ViewModel"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    
    <UserControl.Resources>
        <SolidColorBrush x:Key="SelectedBackgroundBrush" Color="Transparent" />
        <SolidColorBrush x:Key="DisabledForegroundBrush" Color="Transparent" />
        <Style x:Key="{x:Type  ListBoxItem}" TargetType="ListBoxItem">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Border Name="Border" Padding="2" SnapsToDevicePixels="true" Background="Transparent">
                            <ContentPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="Border" Property="Background"  Value="{StaticResource SelectedBackgroundBrush}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">

            <Grid>

                <SubVersionOne:LoginView x:Name="loginView" />
                <SubVersionOne:SettingsView x:Name="settingsView"/>
                <Grid x:Name="workItemGrid">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"></RowDefinition>
                    </Grid.RowDefinitions>
                    <StackPanel Grid.Row="0" Margin="5" Orientation="Horizontal">
                        <Button Width="100" Padding="5" Margin="2" HorizontalAlignment="Left" Click="Button_Click_2"  ToolTip="Logins into VersionOne and downloads all your work items, caching them locally.">Refresh</Button>
                        <Button Width="100" Padding="5" Margin="2"  HorizontalAlignment="Left"  Click="Button_Click_3"  ToolTip="Removes a locally cached password file.">Clear Password</Button>
                        <Button Width="100" Padding="5" Margin="2"  HorizontalAlignment="Left" Click="Button_Click_4" ToolTip="Manage settings." >Settings</Button>




                    </StackPanel>
                    <ScrollViewer Grid.Row="1">
                        <ListBox ItemsSource="{Binding Items,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto">

                                            </RowDefinition>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>
                                        <StackPanel Orientation="Horizontal" Grid.Row="0">
                                            <CheckBox IsChecked="{Binding Selected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"    VerticalAlignment="Center">
                                                <StackPanel Orientation="Horizontal">

                                                    <TextBlock Text="{Binding ID}" FontWeight="Normal" Foreground="Green"/>
                                                    <TextBlock Text=":"/>
                                                    <TextBlock Text="{Binding Name}" FontWeight="Normal"/>

                                                </StackPanel>
                                            </CheckBox>

                                            
                                        </StackPanel>
                                        <ItemsControl Grid.Row="1" ItemsSource="{Binding Children,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate>
                                                    <StackPanel Orientation="Horizontal" Grid.Row="0" Margin="20,0,0,0">
                                                        <CheckBox Checked="CheckBox_Checked_1" VerticalAlignment="Center" IsChecked="{Binding Selected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  >
                                                            <StackPanel Orientation="Horizontal">

                                                                <TextBlock Text="{Binding ID}" FontWeight="Normal" Foreground="Blue"/>
                                                                <TextBlock Text=":"/>
                                                                <TextBlock Text="{Binding Name}" FontWeight="Normal"/>

                                                            </StackPanel>

                                                        </CheckBox>
                                                       
                                                    </StackPanel>
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                        </ItemsControl>
                                    </Grid>

                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </ScrollViewer>
                    <StackPanel Grid.Row="2" Margin="5" Orientation="Horizontal">
                        <Button Content="Ok" Click="Button_Click_1" HorizontalAlignment="Left" Width="100" Padding="5" Margin="2"/>
                        <Button Content="Cancel" Click="Button_Click_1" HorizontalAlignment="Left" Width="100" Padding="5" Margin="2"/>

                    </StackPanel>
                </Grid>

            </Grid>

        </Grid>
        <Grid Grid.Row="1" Margin="2">
            <Grid.Background>
                <SolidColorBrush Color="#6da4c0"></SolidColorBrush>
            </Grid.Background>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="100"/>
            </Grid.ColumnDefinitions>
            <TextBlock x:Name="statusMessage" Foreground="White" Padding="5"/>
            <ProgressBar x:Name="progressBar" VerticalAlignment="Center" Height="15" BorderThickness="0" Background="Transparent" IsIndeterminate="{Binding IsBusy}" Grid.Column="1"/>
        </Grid>
    </Grid>
</UserControl>
